/**
 * 
 */
package com.gragra.evaluateNouns;
import java.util.Arrays;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import com.gragra.sampling.sequentialStructure.ExtensionInformationValue;
import com.gragra.sequentiaDataGenerator.Segmentation;
/**
 * This class wraps another implementation of Segmentation and adds ExtensionLevels information for
 * finite ExtensionLevels, it does this by matching the tag assigned to a word against Strings in a map
 * and assigns the ExtensionLevelInfomationValue information that is in the map, using the getLevel method
 * to find out to which level the information belongs.
 * It uses the ObjectArrayList of the wrapped Segmentation to do this.
 * @author Christoph Teichmann
 * 20.04.2013
 */
public class ExtendingSegmentation implements Segmentation
{
	
	/**
	 * constructs a new instance that wraps the given Segmentation and makes the given WordType
	 * assignments
	 * @param wrapped
	 * @param assignments
	 */
	public ExtendingSegmentation(Segmentation wrapped,
			Object2ObjectOpenHashMap<String, ExtensionInformationValue> assignments)
	{
		super();
		this.wrapped = wrapped;
		this.assignments = assignments;
	}
	/**
	 * holds the Segmentation that does the initial reading of any input string
	 */
	private final Segmentation wrapped;
	/**
	 * holds the assignments from tags to extension information
	 */
	private final Object2ObjectOpenHashMap<String, ExtensionInformationValue> assignments;
	/* (non-Javadoc)
	 * @see com.gragra.sequentiaDataGenerator.Segmentation#segment(java.lang.String)
	 */
	@Override
	public ObjectArrayList<String[]> segment(String s)
	{
		ObjectArrayList<String[]> ret = this.wrapped.segment(s);
		for(int i=0;i<ret.size();++i)
		{
			String[] elems = ret.get(i);
			if(assignments.containsKey(elems[1]))
			{
				elems = Arrays.copyOf(elems, elems.length+2);
				ExtensionInformationValue eiv = assignments.get(elems[1]);
				elems[elems.length-2] = eiv.getLevel().name();
				elems[elems.length-1] = eiv.name();
				ret.set(i, elems);
			}
		}
		return ret;
	}
}